//
//  SecondViewController.m
//  IPhoneX适配
//
//  Created by 训网高 on 2018/4/28.
//  Copyright © 2018年 训网高. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()
{
    UIButton *typeBtn;
}
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor brownColor];
    self.title = @"分类";
    
    
    NSArray *btnTitleArray = @[@"游学",@"商学院",@"名人堂",@"户外探险"];
    CGFloat imageWidth = 0;
    imageWidth = [UIImage imageNamed:@"shouye"].size.width;
    
    CGFloat X = 0;
    for (int i = 0; i < btnTitleArray.count; i++) {
        NSString *string = btnTitleArray[i];
        CGSize titleSize = [string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 40) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]}
                                                context:nil].size;
        CGFloat titleWidth = titleSize.width;
        
        
        DLog(@"%.2f",(titleWidth+ imageWidth));
        typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        typeBtn.frame = CGRectMake(X, Height_NavBar+ 40, titleWidth+imageWidth, 40);
        typeBtn.backgroundColor = [UIColor whiteColor];
        [typeBtn setImage:[UIImage imageNamed:@"shouye"] forState:UIControlStateNormal];
        [typeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [typeBtn setTitle:btnTitleArray[i] forState:UIControlStateNormal];
        typeBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        
        X = X+ (imageWidth + titleWidth);
        [self.view addSubview:typeBtn];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
